package cate.game.pvp.arena.core;

import cate.game.role.RoleSnapshot;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;
import org.springframework.data.annotation.Transient;

import java.util.Comparator;
import java.util.concurrent.locks.ReentrantLock;

@NoteClass("跨服擂台赛-选手快照")
public class ArenaRoleSnapshot {
    @NoteField("排行")
    public int rank;
    @NoteField("积分")
    public int score;
    @NoteField("上次变更时间")
    public long lastChangeTime;
    @NoteField("战力")
    public long power;
    @NoteField("点赞数")
    public int likeCount;
    @NoteField("是否入榜")
    public boolean active;
    @NoteField("机器人ID 真实玩家为0")
    public int robotId;
    @NoteField("快照")
    public RoleSnapshot snapshot;

    @Transient
    public final ReentrantLock lock = new ReentrantLock();

    @Transient
    @NoteField("排序比较")
    public static final Comparator<? super ArenaRoleSnapshot> COMPARATOR = (Comparator<ArenaRoleSnapshot>) (o1, o2) -> {
        if (o1.score != o2.score) {
            return Integer.compare(o2.score, o1.score);
        }
        return Long.compare(o1.lastChangeTime, o2.lastChangeTime);
    };
}
